import re
from urllib.parse import unquote
from script.get_user_info.config.luogu_config import lg_headers
import requests
import json


# 获取等级分的json
def luogu_json(uid):
    baseurl = "https://www.luogu.com.cn/api/rating/elo?user=" + str(uid) + "&page=1&limit=50"
    response = requests.get(baseurl, headers=lg_headers)
    return response.text

# 获取总过题数的json
def luogu_response(uid):
    baseurl = "https://www.luogu.com.cn/user/" + str(uid)
    response = requests.get(baseurl, headers=lg_headers)
    pattern = re.compile(r'ent\(\"([^\"]+)\"\)')
    result = re.search(pattern=pattern, string=response.text)
    result = result.group(0)
    encoded_str = result[5:-2]
    decoded_str = unquote(encoded_str)
    dict_t = json.loads(decoded_str)
    return dict_t

if __name__ == '__main__':
    print(luogu_json("1585789"))
